package com.ruoyi.zyx.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxCheck;
import com.ruoyi.zyx.service.IZyxCheckService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检定基础信息Controller
 *
 * @author lhs
 * @date 2021-06-02
 */
@RestController
@RequestMapping("/zyx/check")
public class ZyxCheckController extends BaseController
{
    @Autowired
    private IZyxCheckService zyxCheckService;

    /**
     * 查询检定基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZyxCheck zyxCheck)
    {
        startPage();
        List<ZyxCheck> list = zyxCheckService.selectZyxCheckList(zyxCheck);
        return getDataTable(list);
    }

    @GetMapping("/listMyCheck")
    public TableDataInfo listMyCheck(ZyxCheck zyxCheck)
    {
        startPage();
        zyxCheck.setDepartid(SecurityUtils.getLoginUser().getUser().getDeptId());
        List<ZyxCheck> list = zyxCheckService.listMyCheck(zyxCheck);
        return getDataTable(list);
    }

    /**
     * 导出检定基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:check:export')")
    @Log(title = "检定基础信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxCheck zyxCheck)
    {
        List<ZyxCheck> list = zyxCheckService.selectZyxCheckList(zyxCheck);
        ExcelUtil<ZyxCheck> util = new ExcelUtil<ZyxCheck>(ZyxCheck.class);
        return util.exportExcel(list, "检定基础信息数据");
    }

    /**
     * 获取检定基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zyxCheckService.selectZyxCheckById(id));
    }

    /**
     * 新增检定基础信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:check:add')")
    @Log(title = "检定基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxCheck zyxCheck)
    {
        return toAjax(zyxCheckService.insertZyxCheck(zyxCheck));
    }

    /**
     * 修改检定基础信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:check:edit')")
    @Log(title = "检定基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxCheck zyxCheck)
    {
        return toAjax(zyxCheckService.updateZyxCheck(zyxCheck));
    }

    /**
     * 删除检定基础信息
     */
    @PreAuthorize("@ss.hasPermi('zyx:check:remove')")
    @Log(title = "检定基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zyxCheckService.deleteZyxCheckByIds(ids));
    }
}
